/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package jforum.actions;

/**
 *
 * @author Вадим
 */
import java.util.HashMap;
import java.util.Map;

public class ActionFactory {
     protected Map map = defaultMap();

     public ActionFactory() {
          super();
     }
     public Action create(String actionName) {
          Class action_class = (Class) map.get(actionName);
          if (action_class == null)
               throw new RuntimeException(getClass() + " was unable to find an action named '" + actionName + "'.");
          Action actionInstance = null;
          try {
               actionInstance = (Action) action_class.newInstance();
          } catch (Exception e) {
               e.printStackTrace();
          }

          return actionInstance;
     }
     protected Map defaultMap() {
          Map map = new HashMap();

          map.put("ViewLoginForm",ViewLoginFormAction.class);
          map.put("Register", RegisterAction.class);
          map.put("Login", LoginAction.class);
          map.put("ViewProfile", ViewProfileAction.class);
          map.put("ViewMessage", ViewMessageAction.class);
          map.put("ViewMessagesForm", ViewMessagesFormAction.class);
          map.put("ViewPostForm", ViewPostFormAction.class);
          map.put("Post", PostAction.class);
          map.put("ViewUsers", ViewUsersAction.class);
          map.put("ViewServicePage", ViewServicePageAction.class);
          map.put("ProcessUsers", ProcessUsersAction.class);
          map.put("Search", SearchAction.class);
          map.put("SearchAuthor", SearchAuthorAction.class);
          map.put("DeleteMessage", DeleteMessageAction.class);

          return map;
     }
}

